//
//  LYPhoto.m
//  LYPhotoBrowser
//
//  Created by LvYuan on 16/12/12.
//  Copyright © 2016年 LvYuan. All rights reserved.
//

#import "LYPhoto.h"
#import "UIImageView+WebCache.h"
@implementation LYPhoto

- (UIImage *)thumbImage{
    if (self.largeImage) {//有大图直接返回大图
        return self.largeImage;
    }
    
    //尝试从磁盘获取缩略图
    if ([[SDImageCache sharedImageCache]diskImageExistsWithKey:self.thumbPicUrl]) {
        return [[SDImageCache sharedImageCache]imageFromDiskCacheForKey:self.thumbPicUrl];
    }

    return [LYPhoto placeHolderFillColorImage];
}

- (UIImage *)largeImage{
    if ([[SDImageCache sharedImageCache]diskImageExistsWithKey:self.largePicUrl]) {
        return [[SDImageCache sharedImageCache]imageFromDiskCacheForKey:self.largePicUrl];
    }
    return _largeImage;
}

/**
 人造图

 @return image
 */
+ (UIImage *)placeHolderFillColorImage{
    CGSize imageSize =CGSizeMake(2,2);
    UIGraphicsBeginImageContextWithOptions(imageSize,0, [UIScreen mainScreen].scale);
    [[UIColor colorWithWhite:0.1 alpha:1] set];
    UIRectFill(CGRectMake(0,0, imageSize.width, imageSize.height));
    UIImage *pressedColorImg =UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return pressedColorImg;
}

@end
